package com.kuangstudy.collection.list;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;

/**
 * ClassName: Demo2
 * date: 2021/07/12 12:23:10
 *
 * @author zlk
 */
public class Demo2 {
    public static void main(String[] args) {
        List list = new ArrayList<>();
        list.add("苹果");
        list.add("小米");
        list.add("华为");
//        System.out.println(list);
//        list.remove("苹果");
//        System.out.println(list);
//        String o = (String) list.get(0);
//        System.out.println(o);
        /*迭代器遍历集合*/
//        Iterator iterator = list.iterator();
//        while (iterator.hasNext()){
//            Object next = iterator.next();
//            System.out.println(next);
//        }
        ListIterator listIterator = list.listIterator();
        while (listIterator.hasNext()){
            System.out.println(listIterator.next());
        }
        /*反方向遍历列表*/
        while (listIterator.hasPrevious()){
            System.out.println(listIterator.previous());
        }
    }
}
